#!/bin/bash
# jimgutil native 库编译脚本
# author guyadong
sh_folder=$(dirname $(readlink -f $0))
folder_name=$(basename $sh_folder) 
# 定义编译的版本类型(DEBUG|RELEASE)
build_type=RELEASE
typeset -u arg1=$1
[ "$arg1" = "DEBUG" ] && build_type=$arg1
echo build_type=$build_type

pushd $sh_folder/.. >/dev/null

[ -d $folder_name.prj ] && rm -fr $folder_name.prj
mkdir $folder_name.prj

pushd $folder_name.prj >/dev/null

install_prefix=$sh_folder/release/jimgutil_linux_x86_64
res_folder=$sh_folder/../jimgutil/src/main/resources/lib/linux-x86-64/

cmake "$sh_folder" -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=$build_type \
	-DCMAKE_INSTALL_PREFIX=$install_prefix

cmake --build . --target install --config release -- -j8 \
	&& mkdir -p $res_folder \
	&& cp -afv $install_prefix/lib/libjimgutil_jni.so $res_folder

popd >/dev/null

popd >/dev/null
